<?php
/**
 * Autor:   Miguel A. Zilli
 * Email:   miguelzilli@gmail.com
 */

class Canal extends AppModel {
    var $name = 'Canal';
    var $useTable = 'canales';
    var $primaryKey = 'id';
    var $displayField = 'nombre_canal';
    var $recursive = 0;
    var $order=array(
        'Canal.nombre_canal'=>'ASC'
    );

    var $validate = array(
        'nombre_canal' =>array(
            array('rule'=>'isUnique','message'=>'Error: Item existente.'),
            array('rule'=>'notEmpty','message'=>'Debe completar este dato.','required'=>true)
        )
    );

    //The Associations below have been created with all possible keys, those that are not needed can be removed
    var $hasMany = array(
        'Comercializacion' => array(
            'className' => 'Comercializacion',
            'foreignKey' => 'canal_id',
            'dependent' => false
        ),
        'CanalesRevision' => array(
            'className' => 'CanalesRevision',
            'foreignKey' => 'canal_id',
            'dependent' => false
        )
    );

    public function beforeSave(){
        if(!empty($this->data['Canal'])){
            foreach($this->data['Canal'] as $campo=>$valor){
                $this->data['Canal'][$campo]=strtoupper($valor);
            }
        }
        return true;
    }
}
?>